﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Globalization;
using ShredTheLog.Api.DataContracts;
using ShredTheLog.Api;

namespace ShredTheLog.Converters
{
    public sealed class UserLocationConverter : ConverterBase, IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values != null && values.Length == 2 && values[0] != null && values[1] is string)
            {
                var country = CountryConverter.Default.Convert((Country)values[0]);
                var location = (string)values[1];
                if (!String.IsNullOrEmpty(location))
                    return String.Format(CultureInfo.CurrentCulture, "{0} ({1})", location, country);
                else
                    return country;
            }
            else
                return null;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        public static readonly UserLocationConverter Default = new UserLocationConverter();
    }
}
